/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// const BigNumber = require('./bignumber') 
import BigNumber from './bignumber' 
 
const BASE_COUNT=10000;
const LONG_COUNT=100000;

/* if it is an positive number  */
function isPositive_Test_01(){  
    try {
        let result
        let big = new BigNumber('-65465623545234256430.68947356254134413245984781695498431')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isPositive()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isPositive(false): " + time +" ms") 
        areEqual(false,result)

        // print(result)  
    } catch (err) {
        throw('error ' + err)
    }  
}
/* if it is an positive number  */
function isPositive_Test_02(){  
    try {
        let result
        let big = new BigNumber('65465623545234256430.68947356254134413245984781695498431')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isPositive()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isPositive(true): " + time +" ms") 
        areEqual(true,result)

        // print(result)  
    } catch (err) {
        throw('error ' + err)
    }  
}
/* if it is negative  */
function negative_Test_01() {  
    try {
        let result
        let big = new BigNumber('-431243215498749643652.1445824548654565234546245553461523543252341')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isNegative()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isNegative(true): " + time +" ms") 
        areEqual(true,result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* if it is negative  */
function negative_Test_02() {  
    try {
        let result
        let big = new BigNumber('431243215498749643652.1445824548654565234546245553461523543252341')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isNegative()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isNegative(false): " + time +" ms") 
        areEqual(false,result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
}

/* Expected results and actual results verification  */
function areEqual(expected, actual) {
    // If expected and actual are both NaN, consider them equal.
    if (expected === actual || expected !== expected && actual !== actual) {
        // print('Success')
    } else {
        let error = 
        '  Failed areEqual test' +
        '  Expected: ' + expected +
        '  Actual:   ' + actual
        ;
        throw(error) 
    }
}

// function print(s){
//     console.log(s);
// }

/*  Benchmark  */
function bignumberRun() {  
    isPositive_Test_01()  
    isPositive_Test_02()  
    negative_Test_01() 
    negative_Test_02()   
}
bignumberRun()